(function() {
	var app = angular.module('targetConfigAPP', [ 'ui.bootstrap' ]);
	app.controller(
					'targetConfigController',
					function($http,$scope, $log, $uibModal) {
						$scope.insertComponent = {};
						$scope.deleteComponent = {};
						var controller = this;
						controller.parameter = {};
						controller.queryParameter = "";
						this.warningConfigList = [];
						this.indexList = [];
						this.queryCondition = {
							"monitoringIndex" : "",
							"page" : 1,
							"size" : 5,
						};
						this.paginationInfo = {
							"maxSize" : 5,
							"totalPages" : 0,
							"totalElements" : 0
						};
						//分页跳转
						$scope.clickEven = function(){
							controller.queryCondition.page = controller.queryCondition.forwordPage;
							loadData();
						}
						$scope.enterEvent = function(e) {
							var keycode = window.event ? e.keyCode : e.which;
							if (keycode == 13) {
								$scope.clickEvent();
							}
						}
						// 搜索事件
						this.search = function() {
							loadData();
						}

						// 重置事件
						this.reset = function() {
							this.queryCondition = {
									"monitoringIndex" : "",
									"page" : 1,
									"size" : 5,
								};
						}
						
						
						// 程序初期化
						this.init = function() {
							loadData();loadkpi();
							
						}
						this.init();

						
						//加载kpi (selected的框里的内容)
						function loadkpi(){
							var basePath = $scope.getAppBasePath();
							// 后台调用
							 $.ajax({
							 type : "POST",
							 url : basePath + "/data/getWarningMonitoringKpi",
							 dataType : "json",
							 contentType : "application/json",
							 //data : JSON.stringify(controller.parameter),
							 success : function(data) {
							 var jsonResult = angular.fromJson(data);
							 console.log(jsonResult);
							 controller.indexList = jsonResult;
							 //手动刷新
							 $scope.$apply();  
							 }
							 });
						}
						
						//加载数据
						function loadData(){
							// 参数获取
							controller.parameter.monitoringIndex = controller.queryCondition.monitoringIndex ||"";
							controller.parameter.page = controller.queryCondition.page;
							controller.parameter.size = controller.queryCondition.size;
							var basePath = $scope.getAppBasePath();
							$.ajax({
								 type : "POST",
								 url : basePath + "/data/getWarningConfig",
								 dataType : "json",
								 contentType : "application/json",
								 data : JSON.stringify(controller.parameter),
								 success:function(data){
									 var jsonResult = angular.fromJson(data);
									 console.log(jsonResult);
									 controller.warningConfigList = jsonResult.list;
									 controller.paginationInfo.totalPages = jsonResult.pages;
									 controller.paginationInfo.totalElements = jsonResult.total;
									//手动刷新
									 $scope.$apply();  
								 }
							})
						}
						
						//
						
						
					})
			
			
})();